##############################
#
# Doxygen cmake file 
# You can define here doxygen generation specific options
# 
# More about cmake : www.cmake.org


IF( DOC_GENERATE STREQUAL "ON" AND NOT DOXYGEN_FOUND )
  MESSAGE( FATAL_ERROR "Doxygen is needed to generate documentation" )
ENDIF( DOC_GENERATE STREQUAL "ON" AND NOT DOXYGEN_FOUND )

IF( DOC_GENERATE STREQUAL "ON" )

  # Configure Doxyfile with version and output dir
  FILE( READ ${CMAKE_CURRENT_SOURCE_DIR}/../src/genericvideomodule.h HEADER_H )

  # Extract version
  STRING( REGEX MATCH "[\t ]*#[\t ]*define[\t ]+.*_VERSION_MAJOR[\t ]+\"([0-9]+)\"" VERSION_MAJOR "${HEADER_H}")
  STRING( REGEX REPLACE "[\t ]*#[\t ]*define[\t ]+.*_VERSION_MAJOR[\t ]+\"([0-9]+)\"" "\\1" VERSION_MAJOR "${VERSION_MAJOR}")

  STRING( REGEX MATCH "[\t ]*#[\t ]*define[\t ]+.*_VERSION_MINOR[\t ]+\"([0-9]+)\"" VERSION_MINOR "${HEADER_H}")
  STRING( REGEX REPLACE "[\t ]*#[\t ]*define[\t ]+.*_VERSION_MINOR[\t ]+\"([0-9]+)\"" "\\1" VERSION_MINOR "${VERSION_MINOR}")

  STRING( REGEX MATCH "[\t ]*#[\t ]*define[\t ]+.*_VERSION_REVISION[\t ]+\"([0-9]+)\"" VERSION_REVISION "${HEADER_H}")
  STRING( REGEX REPLACE "[\t ]*#[\t ]*define[\t ]+.*_VERSION_REVISION[\t ]+\"([0-9]+)\"" "\\1" VERSION_REVISION "${VERSION_REVISION}")

  # Set variables
  SET( GENERICVIDEOMODULE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}-r${VERSION_REVISION}" )
  SET( DOXY_OUT_DIR "${OUTPUT_ROOT_DIR_DOC}" )
  IF( DOXYGEN_DOT_FOUND )
        SET( HAVE_DOT "YES" )
  ELSE( DOXYGEN_DOT_FOUND )
        SET( HAVE_DOT "NO" )
  ENDIF( DOXYGEN_DOT_FOUND )

  # Generate configured Doxyfile
  CONFIGURE_FILE(
        "${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in"
        "${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile"
        ESCAPE_QUOTES
  )

  # Add rule to build doc
  # NOTE: Rule (docs) will always be added, but if DOC_GENERATE is set to "ON",
  # this rule will be build automatically when building application; otherwises,
  # you will have to type make docs to build doc
  IF( DOC_GENERATE STREQUAL "ON" )
        ADD_CUSTOM_TARGET( docs
          ALL
          ${DOXYGEN_EXECUTABLE}
          ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
          WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
        )
  ENDIF( DOC_GENERATE STREQUAL "ON" )

  MESSAGE( STATUS "Doc for  will be build in '${DOXY_OUT_DIR}')" )

ENDIF( DOC_GENERATE STREQUAL "ON" )

